import store from '../store/store';
import { setShowOverlay, setMessages } from '../store/actions';

export default class WebRTCHandler {
    constructor(){
        //指定请求的媒体类型和相对应的参数。
        this.defaultConstraints = {
            audio : true,
            video : { width : '480', height : '360' }
        };

        //仅开启音频链接
        this.onlyAudioConstraints = {
            audio : true,
            video : false,
        };

        this.localStream = null;
    }

    async getLocalPreviewAndInitRoomConnection (isRoomHost, identity, roomId = null, onlyAudio){
        //判断是开启音频还是音视频
        //const constrains = onlyAudio ? this.onlyAudioConstraints : this.defaultConstraints;
        const constrains = this.onlyAudioConstraints;
        navigator.mediaDevices.getUserMedia(constrains).then((stream) => {
            console.log('成功获取本地媒体流');
            this.localStream = stream;
            this.showLocalVideoPreview(this.localStream);
            //派发action隐藏加载动画
            store.dispatch(setShowOverlay(false));
            //初始化房间连接
            
        }).catch((error) => {
            console.log('无法获取本地媒体流！');
            console.log(error);
        })
    }

    showLocalVideoPreview = (stream) => {
    
    }
}
